In [17]:
import cv2
import matplotlib.pyplot as plt
import numpy as np
In [20]:
#  Ideal low Pass Filter
f = cv2.imread(r"C:\Users\Dell\OneDrive\Documents\Chirag\MCA\SEM2\IP\IP Programs\Images\CLogo.png",0)

plt.imshow(f, cmap="gray")
plt.title("f(x,y)")
plt.axis("off")
plt.show()

F = np.fft.fft2(f)
plt.imshow(np.log1p(np.abs(F)), cmap="gray")
plt.title("F")
plt.axis("off")
plt.show()

Fshift = np.fft.fftshift(F)
plt.imshow(np.log1p(np.abs(Fshift)), cmap="gray")
plt.title("F(U,V)")
plt.axis("off")
plt.show()

M,N = f.shape
H = np.zeros((M,N), dtype=np.float32)
D0 = 50

for u in range(M):
    for v in range(N):
        D = np.sqrt((u-M/2) ** 2 + (v-N/2) ** 2)
        if D <= D0:
            H[u,v] = 1
        else:
            H[u,v] = 0

plt.imshow(H, cmap="gray")
plt.title("H")
plt.axis("off")
plt.show()

Gshift = Fshift * H
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("G(U,V) = F(U,V) * H(U,V)")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("Ginverse(U,V)")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Smoothing ILPF")
plt.axis("off")
plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [25]:
#  Gaussian low Pass Filter
f = cv2.imread(r"C:\Users\Dell\OneDrive\Documents\Chirag\MCA\SEM2\IP\IP Programs\Images\CLogo.png",0)

plt.imshow(f, cmap="gray")
plt.title("f(x,y)")
plt.axis("off")
plt.show()

F = np.fft.fft2(f)
plt.imshow(np.log1p(np.abs(F)), cmap="gray")
plt.title("F")
plt.axis("off")
plt.show()

Fshift = np.fft.fftshift(F)
plt.imshow(np.log1p(np.abs(Fshift)), cmap="gray")
plt.title("F(U,V)")
plt.axis("off")
plt.show()

M,N = f.shape
H = np.zeros((M,N), dtype=np.float32)
D0 = 50

for u in range(M):
    for v in range(N):
        D = np.sqrt((u-M/2) ** 2 + (v-N/2) ** 2)
        if D <= D0:
            H[u,v] = 1
        else:
            H[u,v] = 0

plt.imshow(H, cmap="gray")
plt.title("H")
plt.axis("off")
plt.show()

Gshift = Fshift * H
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("G(U,V) = F(U,V) * H(U,V)")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("Ginverse(U,V)")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Smoothing ILPF")
plt.axis("off")
plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [22]:
# Butterworth low Pass Filter
f = cv2.imread(r"C:\Users\Dell\OneDrive\Documents\Chirag\MCA\SEM2\IP\IP Programs\Images\CLogo.png",0)

plt.imshow(f, cmap="gray")
plt.title("f(x,y)")
plt.axis("off")
plt.show()

F = np.fft.fft2(f)
plt.imshow(np.log1p(np.abs(F)), cmap="gray")
plt.title("F")
plt.axis("off")
plt.show()

Fshift = np.fft.fftshift(F)
plt.imshow(np.log1p(np.abs(Fshift)), cmap="gray")
plt.title("F(U,V)")
plt.axis("off")
plt.show()

M,N = f.shape
H = np.zeros((M,N), dtype=np.float32)
D0 = 10
n = 1

for u in range(M):
    for v in range(N):
        D = np.sqrt((u-M/2) ** 2 + (v-N/2) ** 2)
        H[u,v] = 1/(1+(D/D0) ** n)

plt.imshow(H, cmap="gray")
plt.title("H")
plt.axis("off")
plt.show()

Gshift = Fshift * H
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("G(U,V) = F(U,V) * H(U,V)")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("Ginverse(U,V)")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Smoothing ILPF")
plt.axis("off")
plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [ ]:
 
In [23]:
# Ideal High Pass Filter
f = cv2.imread(r"C:\Users\Dell\OneDrive\Documents\Chirag\MCA\SEM2\IP\IP Programs\Images\CLogo.png",0)

plt.imshow(f, cmap="gray")
plt.title("f(x,y)")
plt.axis("off")
plt.show()

F = np.fft.fft2(f)
plt.imshow(np.log1p(np.abs(F)), cmap="gray")
plt.title("F")
plt.axis("off")
plt.show()

Fshift = np.fft.fftshift(F)
plt.imshow(np.log1p(np.abs(Fshift)), cmap="gray")
plt.title("F(U,V)")
plt.axis("off")
plt.show()

M,N = f.shape
H = np.zeros((M,N), dtype=np.float32)
D0 = 50

for u in range(M):
    for v in range(N):
        D = np.sqrt((u-M/2) ** 2 + (v-N/2) ** 2)
        if D <= D0:
            H[u,v] = 1
        else:
            H[u,v] = 0

plt.imshow(H, cmap="gray")
plt.title("H")
plt.axis("off")
plt.show()

Gshift = Fshift * H
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("G(U,V) = F(U,V) * H(U,V)")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("Ginverse(U,V)")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Smoothing ILPF")
plt.axis("off")
plt.show()

Hhighpass = 1 - H
plt.imshow(Hhighpass, cmap="gray")
plt.title("Hhighpass")
plt.axis("off")
plt.show()

Gshift = Fshift * Hhighpass
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("Gshift")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("G")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Sharpening ILPF")
plt.axis("off")
plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [24]:
#  Gaussian High Pass Filter
f = cv2.imread(r"C:\Users\Dell\OneDrive\Documents\Chirag\MCA\SEM2\IP\IP Programs\Images\CLogo.png",0)

plt.imshow(f, cmap="gray")
plt.title("f(x,y)")
plt.axis("off")
plt.show()

F = np.fft.fft2(f)
plt.imshow(np.log1p(np.abs(F)), cmap="gray")
plt.title("F")
plt.axis("off")
plt.show()

Fshift = np.fft.fftshift(F)
plt.imshow(np.log1p(np.abs(Fshift)), cmap="gray")
plt.title("F(U,V)")
plt.axis("off")
plt.show()

M,N = f.shape
H = np.zeros((M,N), dtype=np.float32)
D0 = 10

for u in range(M):
    for v in range(N):
        D = np.sqrt((u-M/2) ** 2 + (v-N/2) ** 2)
        H[u,v] = np.exp(-D**2 / (2*D0*D0))

plt.imshow(H, cmap="gray")
plt.title("H")
plt.axis("off")
plt.show()

Gshift = Fshift * H
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("G(U,V) = F(U,V) * H(U,V)")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("Ginverse(U,V)")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Smoothing ILPF")
plt.axis("off")
plt.show()

Hhighpass = 1 - H
plt.imshow(Hhighpass, cmap="gray")
plt.title("Hhighpass")
plt.axis("off")
plt.show()

Gshift = Fshift * Hhighpass
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("Gshift")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("G")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Sharpening ILPF")
plt.axis("off")
plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [26]:
#  Butterworth High Pass Filter
f = cv2.imread(r"C:\Users\Dell\OneDrive\Documents\Chirag\MCA\SEM2\IP\IP Programs\Images\CLogo.png",0)

plt.imshow(f, cmap="gray")
plt.title("f(x,y)")
plt.axis("off")
plt.show()

F = np.fft.fft2(f)
plt.imshow(np.log1p(np.abs(F)), cmap="gray")
plt.title("F")
plt.axis("off")
plt.show()

Fshift = np.fft.fftshift(F)
plt.imshow(np.log1p(np.abs(Fshift)), cmap="gray")
plt.title("F(U,V)")
plt.axis("off")
plt.show()

M,N = f.shape
H = np.zeros((M,N), dtype=np.float32)
D0 = 10
n = 1

for u in range(M):
    for v in range(N):
        D = np.sqrt((u-M/2) ** 2 + (v-N/2) ** 2)
        H[u,v] = 1/(1+(D/D0) ** n)

plt.imshow(H, cmap="gray")
plt.title("H")
plt.axis("off")
plt.show()

Gshift = Fshift * H
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("G(U,V) = F(U,V) * H(U,V)")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("Ginverse(U,V)")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Smoothing ILPF")
plt.axis("off")
plt.show()

Hhighpass = 1 - H
plt.imshow(Hhighpass, cmap="gray")
plt.title("Hhighpass")
plt.axis("off")
plt.show()

Gshift = Fshift * Hhighpass
plt.imshow(np.log1p(np.abs(Gshift)), cmap="gray")
plt.title("Gshift")
plt.axis("off")
plt.show()

G = np.fft.ifftshift(Gshift)
plt.imshow(np.log1p(np.abs(G)), cmap="gray")
plt.title("G")
plt.axis("off")
plt.show()

g = np.abs(np.fft.ifft2(G))
plt.imshow(g, cmap="gray")
plt.title("g(x,y) = Image Sharpening ILPF")
plt.axis("off")
plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [ ]: